#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		int t, h, m;
		cin>>t>>h;
		getchar();
		cin>>m;
		m += h*60+t;
		cout<<m/60<<":"<<m%60<<endl;
	}
	return 0;
}

